package com.zlw.framework.starter;

import com.zlw.framework.beans.BeanFactory;
import com.zlw.framework.core.ClassScanner;
import com.zlw.framework.web.handler.HandlerManager;
import com.zlw.framework.web.server.TomcatServer;
import org.apache.catalina.LifecycleException;

import java.util.List;

/**
 * @ClassName MiniApplication
 * @Description TODO
 * @Author zhaoluowei
 * @Date 2020/1/28  16:00
 * @Version 1.0
 */

public class MiniApplication {
    //应用入口的 参数
    public static void run(Class<?> cls, String[] args) {
        System.out.println("Hello mini-spring!");
        TomcatServer tomcatServer = new TomcatServer(args);
        try {
            System.out.println("--------------- start ------------");
            tomcatServer.startServer();
            System.out.println("--------------- end ------------");
            System.out.println("传进来的包名 --> " + cls.getPackage().getName());
            List<Class<?>> classList = ClassScanner.scanClass(cls.getPackage().getName());

            //bean工厂 初始化bean
            BeanFactory.initBean(classList);

            HandlerManager.resolveMappingHandler(classList);

            classList.forEach(it -> System.out.println(it.getName()));

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

}
